package gui.customControl;

import java.awt.Dimension;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * Log window used in the game. A singleton.
 * 
 * @author Julien
 * 
 */
public class LogWindow extends JScrollPane {
	private static final long serialVersionUID = -5432544548255050532L;
	private static LogWindow m_instance;

	private final JTextArea m_text = new JTextArea();

	/**
	 * Gets the LogWindow singleton.
	 * 
	 * @return LogWindow object
	 */
	public static LogWindow instance() {
		if (m_instance == null) {
			m_instance = new LogWindow();
		}

		return m_instance;
	}

	/**
	 * Default constructor.
	 */
	public LogWindow() {
		super();
		setViewportView(m_text);
		m_text.setEditable(false);
		setMinimumSize(new Dimension(200, 70));
		setMaximumSize(new Dimension(200, 70));
		setPreferredSize(new Dimension(200, 70));
	}

	/**
	 * Adds a line of text to the window
	 * 
	 * @param msg
	 *            The line to add.
	 */
	public void Log(final String msg) {
		m_text.append(msg + "\n");

		// also display the log to the console
		// System.out.println(msg);
	}
}
